<script type="text/javascript">

</script>

<div id="page_content">
    <h2><?= $this->ref['title'] ?></h2>
    <?= $this->form ?>
</div>

<div id="sidebar">
    <a href="<?= ADMIN_URL . '/pages/modify/a/record/rid/' . $this->ref['id'] . '/id/' . $this->section->id ?>" class="sidebar_button add_button"><?= $this->t->_("New record") ?></a>
    <?php if (isset($this->record)) { ?>
        <br /><a href="#" id="<?= ADMIN_URL . '/pages/modify/a/remove/rid/' . $this->ref['id'] . '/id/' . $this->section->id . '/recid/' . $this->record['id'] ?>" class="sidebar_button delete_button"><?= $this->t->_("Delete record") ?></a>
<?php } ?>
</div>


<script type="text/javascript">
/*Tags autocomplete*/
            $(function() {

                function split( val ) {
                    return val.split( /,\s*/ );
                }
    
                function extractLast( term ) {
                    return split( term ).pop().toLowerCase();
                }
                var way = '' ;
                $( ".tags" )
                // don't navigate away from the field on tab when selecting an item
                .bind( "keydown", function( event ) {
                    way = "<?= ADMIN_URL ?>/forms/tags/object/" + $( this ).attr("rel");
                    if ( event.keyCode === $.ui.keyCode.TAB &&
                        $( this ).data( "autocomplete" ).menu.active ) {
                        event.preventDefault();
                    }
                })
                .autocomplete({
                    source: function( request, response ) {
                        $.getJSON( way, {
                            term: extractLast( request.term )
                        }, response );
                    },
                    search: function() {
                        var term = extractLast( this.value );
                        if ( term.length < 0 ) {
                            return false;
                        }
                    },
                    focus: function() {
                        // prevent value inserted on focus
                        return false;
                    },
                    select: function( event, ui ) {
                        var terms = split( this.value );
                        // remove the current input
                        terms.pop();
                        // add the selected item
                        terms.push( ui.item.value );
                        // add placeholder to get the comma-and-space at the end
                        terms.push( "" );
                        this.value = terms.join( ", " );
                        return false;
                    }
                });
            });
</script>